/*
 * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


// WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION!

import { int32, float32 } from "@koalaui/common"
import { KStringPtr, KBoolean, RuntimeType, runtimeType, isResource, isInstanceOf } from "@koalaui/interop"
import { NodeAttach, remember } from "@koalaui/runtime"
import { ComponentBase } from "./ComponentBase"
import { TypeChecker } from "#components"
import { ArkScrollableCommonMethodComponent } from "./ArkCommon"
import { ArkScrollPeer } from "./peers/ArkScrollPeer"
import { UseEventsProperties } from "./use_properties"
import { ScrollableCommonMethod, NestedScrollOptions, EdgeEffectOptions } from "./ArkCommonInterfaces"
import { ScrollAttribute, ScrollDirection, ScrollOnWillScrollCallback, ScrollOnScrollCallback, OnScrollEdgeCallback, OnScrollFrameBeginCallback, ScrollSnapOptions, OffsetOptions } from "./ArkScrollInterfaces"
import { Callback_Number_Number_Void, Callback_Void } from "./SyntheticDeclarations"
import { VoidCallback } from "./ArkUnitsInterfaces"
import { BarState, Color, EdgeEffect } from "./ArkEnumsInterfaces"
import { Resource } from "./ArkResourceInterfaces"
import { Scroller } from "./ArkScrollerMaterialized"
/** @memo:stable */
export class ArkScrollComponent extends ArkScrollableCommonMethodComponent {
    getPeer(): ArkScrollPeer {
        return (this.peer as ArkScrollPeer)
    }
    /** @memo */
    public setScrollOptions(scroller?: Scroller): this {
        if (this.checkPriority("setScrollOptions")) {
            const scroller_casted = scroller as (Scroller | undefined)
            this.getPeer()?.setScrollOptionsAttribute(scroller_casted)
            return this
        }
        return this
    }
    /** @memo */
    public scrollable(value: ScrollDirection): this {
        if (this.checkPriority("scrollable")) {
            const value_casted = value as (ScrollDirection)
            this.getPeer()?.scrollableAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onScroll(value: ((first: number,last: number) => void)): this {
        if (this.checkPriority("onScroll")) {
            const value_casted = value as (((first: number,last: number) => void))
            this.getPeer()?.onScrollAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onWillScroll(value?: ScrollOnWillScrollCallback): this {
        if (this.checkPriority("onWillScroll")) {
            const value_casted = value as (ScrollOnWillScrollCallback | undefined)
            this.getPeer()?.onWillScrollAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onDidScroll(value: ScrollOnScrollCallback): this {
        if (this.checkPriority("onDidScroll")) {
            const value_casted = value as (ScrollOnScrollCallback)
            this.getPeer()?.onDidScrollAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onScrollEdge(value: OnScrollEdgeCallback): this {
        if (this.checkPriority("onScrollEdge")) {
            const value_casted = value as (OnScrollEdgeCallback)
            this.getPeer()?.onScrollEdgeAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onScrollStart(value: VoidCallback): this {
        if (this.checkPriority("onScrollStart")) {
            const value_casted = value as (VoidCallback)
            this.getPeer()?.onScrollStartAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onScrollEnd(value: (() => void)): this {
        if (this.checkPriority("onScrollEnd")) {
            const value_casted = value as ((() => void))
            this.getPeer()?.onScrollEndAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onScrollStop(value: VoidCallback): this {
        if (this.checkPriority("onScrollStop")) {
            const value_casted = value as (VoidCallback)
            this.getPeer()?.onScrollStopAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public scrollBar(value: BarState): this {
        if (this.checkPriority("scrollBar")) {
            const value_casted = value as (BarState)
            this.getPeer()?.scrollBarAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public scrollBarColor(value: Color | number | string): this {
        if (this.checkPriority("scrollBarColor")) {
            const value_casted = value as (Color | number | string)
            this.getPeer()?.scrollBarColorAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public scrollBarWidth(value: number | string): this {
        if (this.checkPriority("scrollBarWidth")) {
            const value_casted = value as (number | string)
            this.getPeer()?.scrollBarWidthAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onScrollFrameBegin(value: OnScrollFrameBeginCallback): this {
        if (this.checkPriority("onScrollFrameBegin")) {
            const value_casted = value as (OnScrollFrameBeginCallback)
            this.getPeer()?.onScrollFrameBeginAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public nestedScroll(value: NestedScrollOptions): this {
        if (this.checkPriority("nestedScroll")) {
            const value_casted = value as (NestedScrollOptions)
            this.getPeer()?.nestedScrollAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public enableScrollInteraction(value: boolean): this {
        if (this.checkPriority("enableScrollInteraction")) {
            const value_casted = value as (boolean)
            this.getPeer()?.enableScrollInteractionAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public friction(value: number | Resource): this {
        if (this.checkPriority("friction")) {
            const value_casted = value as (number | Resource)
            this.getPeer()?.frictionAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public scrollSnap(value: ScrollSnapOptions): this {
        if (this.checkPriority("scrollSnap")) {
            const value_casted = value as (ScrollSnapOptions)
            this.getPeer()?.scrollSnapAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public enablePaging(value: boolean): this {
        if (this.checkPriority("enablePaging")) {
            const value_casted = value as (boolean)
            this.getPeer()?.enablePagingAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public initialOffset(value: OffsetOptions): this {
        if (this.checkPriority("initialOffset")) {
            const value_casted = value as (OffsetOptions)
            this.getPeer()?.initialOffsetAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public edgeEffect(edgeEffect: EdgeEffect, options?: EdgeEffectOptions): this {
        if (this.checkPriority("edgeEffect")) {
            const edgeEffect_casted = edgeEffect as (EdgeEffect)
            const options_casted = options as (EdgeEffectOptions | undefined)
            this.getPeer()?.edgeEffectAttribute(edgeEffect_casted, options_casted)
            return this
        }
        return this
    }
    public applyAttributesFinish(): void {
        // we calls this function outside of class, so need to make it public
        super.applyAttributesFinish()
    }
}

/** @memo */
export function ArkScroll(
  /** @memo */
  style: ((attributes: ArkScrollComponent) => void) | undefined,
  /** @memo */
  content_: (() => void) | undefined,
  scroller?: Scroller | undefined
) {
    const receiver = remember(() => {
        return new ArkScrollComponent()
    })
    NodeAttach<ArkScrollPeer>((): ArkScrollPeer => ArkScrollPeer.create(receiver), (_: ArkScrollPeer) => {
        receiver.setScrollOptions(scroller)
        style?.(receiver)
        content_?.()
        receiver.applyAttributesFinish()
    })
}
